package com.qq2008.game.stzb.server;

import com.qq2008.game.stzb.jdo.Role;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 角色管理器
 */
@Component
public class RoleServer {

    private static RoleServer roleServer;
    private static Map<Integer, Role> roleMap = null;

    // 获取角色信息
    public static Role getRole(int roleId) {
        Map<Integer, Role> roleMap1 = getRoleServer().getRoleMap();
        return roleMap1.get(roleId);
    }

    // 更新角色信息
    public static void saveRole(Role role) {
        Map<Integer, Role> roleMap1 = getRoleServer().getRoleMap();
        roleMap1.put(role.getId(), role);
        roleMap = roleMap1;
    }

    // 获取角色管理器
    private static RoleServer getRoleServer() {
        if (roleServer == null) {
            roleServer = new RoleServer();
        }
        return roleServer;
    }

    // 获取角色列表
    private Map<Integer, Role> getRoleMap() {
        if (null == roleMap) {
            roleMap = new HashMap<>();
        }
        return roleMap;
    }

    //初始化静态参数
    @PostConstruct
    public void init() {
        roleServer = this;
    }

}
